<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class IndexController extends Controller
{
    //后台主页index
    public function index()
    {
    	// return '后台主页';
    	return view('admin.index');
    }
    // 数据统计
    public function userajax(Request $request)
    {
    	$data['u'] = DB::table('users') -> count();
    	$data['c'] = DB::table('comment') -> count();
    	$data['g'] = DB::table('goods') -> count();
    	$data['e'] = DB::table('users_edit') -> count();
        if(!$data)
        {
            $data['u'] = 'Loading';
            $data['c'] = 'Loading';
            $data['g'] = 'Loading';
            $data['e'] = 'Loading';
            return response() -> json($data);
        } 
    	return response() -> json($data);
    }

    //动态评论
    public function comajax()
    {   

        //全局变量
        $num = 5;
        //查询数据库
        $data = DB::table('comment') -> orderby('id', 'desc') -> take($num) -> get();
        // 判断
        if(!$data)
        {
            return response() -> json('5');
        }

        return response() -> json($data);
    }

}
